package com.jianyun.jyzs.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;


import com.jianyun.jyzs.R;
import com.jianyun.jyzs.bean.EngineeringResult;
import com.jianyun.jyzs.utils.LoginCache;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by mlli on 2017/10/26.
 * 工程动态的附件显示
 */

public class EngineerAttachAdapter extends RecyclerView.Adapter{
    private Context context;
    private List<EngineeringResult.EngineerBean.AttachmentBean> list;
    //private final String bcfHttpUrl;

    public EngineerAttachAdapter(Context context, List<EngineeringResult.EngineerBean.AttachmentBean> list) {
        this.context = context;
        this.list = list;
        //bcfHttpUrl = LoginCache.getInstance().getLoginCache().getBcfHttpUrl();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.image_view, null);
        return new MViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        MViewHolder mHolder = (MViewHolder) holder;
        EngineeringResult.EngineerBean.AttachmentBean bean = list.get(position);
        String phonPath = bean.getPhonPath();
        String photoPath = bean.getPhotoPath();
        String videoPath = bean.getVideoPath();

        int i = attachType(phonPath, photoPath, videoPath);
        switch (i){
            case -1:
                //
                Picasso.with(context).load(R.drawable.rc_complete_hover).into(mHolder.imageview);
                break;
            case 0:
                Picasso.with(context).load(R.drawable.rc_voice_icon_left).into(mHolder.imageview);
                break;
            case 1:
                //Picasso.with(context).load(bean.getPhotoPath()==null?"xxx":bcfHttpUrl+bean.getPhotoPath()).error(R.drawable.rc_image_error).into(mHolder.imageview);
                break;
            case 2:
                Picasso.with(context).load(R.drawable.rc_ac_video_file_icon).into(mHolder.imageview);
                break;
        }
    }

    private int attachType(String phonPath, String photoPath, String videoPath) {
        int type = -1;
        if (phonPath!=null)type=0;
        if (photoPath!=null)type=1;
        if (videoPath!=null)type=2;
        return type;
    }

    @Override
    public int getItemCount() {
        return list.size();
    }


    class MViewHolder extends RecyclerView.ViewHolder{

        private final ImageView imageview;

        public MViewHolder(View itemView) {
            super(itemView);
            imageview = (ImageView) itemView.findViewById(R.id.itemImage);
        }
    }
}
